<?php

namespace application\Module;

use library\Core\Db\CDbCriteria;
use application\Model\EntitystoresModel;
use application\Comm\Func;
use application\Comm\Request;

class Entitystores
{

    /**
     * @param $pid
     * @param array $select
     * @return array
     * 根据位置获取广告
     */
    public function getList($province_id = '',$city='', $select = ['id','phone', 'name', 'area_fix','address'],$limit = 12)
    {
        $criteria = new CDbCriteria();
        $adimageModel = new EntitystoresModel();
        $criteria->select($select);

        $page['now_page'] = Request::getParam('p') ? Request::getParam('p') : 1;
        $page['list_rows'] = Request::getParam('list_rows') ? Request::getParam('list_rows') : $limit;
        $offset = ($page['now_page'] - 1) * $page['list_rows'];
        
        if ($province_id !=''){
	        $criteria->addEqCondition('province_id', $province_id);
        }
        if ($city !=''){
        	$criteria->addEqCondition('city_id', $city);
        }    
        $page['total_rows'] = $adimageModel->getCount($criteria);
        
        $criteria->setOffset($offset);
        $criteria->setLimit($page['list_rows']);
        
         $criteria->addEqCondition('status', 1);
        $criteria->addOrderDesc('order_id');
        
        $data = $adimageModel->getListForArray($criteria);
        return ['data' => $data,'page' => $page];

    }

}
